package com.cq.controller;

import com.cq.pojo.Employee;
import com.cq.pojo.LoginUser;
import com.cq.pojo.Student;
import com.cq.pojo.User;
import com.cq.service.EmployeeService;
import com.cq.service.StuService;
import com.cq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.support.RequestPartServletServerHttpRequest;

import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/student/normal")
public class AddController {

    @Autowired
    private UserService userService;

    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private StuService stuService;

    @RequestMapping("/addAdminView")
    public String addAdminView(){
        return "add/addAdmin";
    }

    @RequestMapping("/addAdmin")
    public String addAdmin(String UserId,String UserName,String password,String root) {
        User user = new User();
        Integer userRoot = Integer.parseInt(root.trim());
        user.setUserId(UserId);
        user.setUserName(UserName);
        user.setPassword(password);
        user.setRoot(userRoot);
        int insert = userService.insertUser(user);
        if(insert>0) {
            System.out.println("添加成功！");
        }
        return "redirect:/student/normal/queryAllUser";
    }

    @RequestMapping("/addStuView")
    public String addStuView(){
        return "add/addStu";
    }

    @RequestMapping("/addStu")
    public String addStu(String Stu_Key,String Stu_Name,String Stu_Sex,
                           String Stu_Enr,String Stu_Birth,String Stu_College,
                           String Stu_Major,String Stu_Polit,String Stu_Address,
                           String Stu_Tel,String password,String root) {
        Student student = new Student();
        Integer stuKey = Integer.parseInt(Stu_Key.trim());
        Integer stuRoot = Integer.parseInt(root.trim());
        student.setStu_Key(stuKey);
        student.setStu_Name(Stu_Name);
        student.setStu_Sex(Stu_Sex);
        student.setStu_Enr(Stu_Enr);
        student.setStu_Birth(Stu_Birth);
        student.setStu_College(Stu_College);
        student.setStu_Major(Stu_Major);
        student.setStu_Polit(Stu_Polit);
        student.setStu_Address(Stu_Address);
        student.setStu_Tel(Stu_Tel);
        student.setPassword(password);
        student.setRoot(stuRoot);
        int insert = userService.insertOneStu(student);
        if(insert>0) {
            System.out.println("添加成功！");
        }
        return "redirect:/student/normal/queryAllStu";
    }

    @RequestMapping("/addEmpView")
    public String addEmpView(){
        return "add/addEmp";
    }

    @RequestMapping("/addEmp")
    public String addEmp(String Emp_Id,String Emp_Name,String Emp_Sex,
                         String Emp_Age,String build_id,String Emp_Job,
                         String Emp_Add,String Emp_Tel,String Emp_Des,
                         String root,String password) {
        Employee employee = new Employee();
        Integer empAge = Integer.parseInt(Emp_Age.trim());
        Integer buildId = Integer.parseInt(build_id.trim());
        Integer empRoot = Integer.parseInt(root.trim());
        employee.setEmp_Id(Emp_Id);
        employee.setEmp_Name(Emp_Name);
        employee.setEmp_Sex(Emp_Sex);
        employee.setEmp_Age(empAge);
        employee.setBuild_id(buildId);
        employee.setEmp_Job(Emp_Job);
        employee.setEmp_Add(Emp_Add);
        employee.setEmp_Tel(Emp_Tel);
        employee.setEmp_Des(Emp_Des);
        employee.setRoot(empRoot);
        employee.setPassword(password);
        int insert = userService.insertOneEmp(employee);
        if(insert>0) {
            System.out.println("添加成功！");
        }
        return "redirect:/student/normal/queryAllEmp";
    }


}
